﻿<cfscript>
/** 
* ORM BookTradesMan
* 
* @hint "Hibernate persistenter t_tradesman. 教材供货商" 
* 
*/ 

component 
	displayname="public.service.orm.senate.BookTradesMan" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="BookTradesMan" 
	table="t_tradesman"
	{

	property type="string" name="TraderID" column="tmid" fieldtype="id" generator="assigned" hint="书商编号";

	property type="string" name="Tradesman" column="tradesman" hint="供货商公司名称";

	property type="string" name="PinYin" column="pyidx" hint="拼音首字母缩写检索";
	property type="string" name="FirstLetter" column="pyid" hint="拼音首字母";

	property name="CourseBooks" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="tmid" cfc="CourseBook" hint="学期教材选用目录";
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		var nextID = numberFormat(1, "0__");
		var checkArray = ORMExecuteQuery("select TraderID from BookTradesMan 
											order by TraderID desc", {}, { maxResults=1 });
		
		/* 
			主键生成规则 CHAR(3)
			
			3位为流水号 书商自动编码
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = numberFormat((checkArray[1] + 1), "0__");
			
		}

		return nextID;
	}

}

</cfscript>